const selectJs = {};

selectJs.setProgressTime = function(value, eleData) {
  if (value && value[0]) {
    if (value[0] instanceof Date) {
      value[0] = value[0].format("yyyy-MM-dd");
    }
    eleData.startTime = value[0];
    // eleData.startTime = eleData.startTime.split("-")[1];
  } else {
    eleData.startTime = null;
  }
  if (value && value[1]) {
    if (value[1] instanceof Date) {
      value[1] = value[1].format("yyyy-MM-dd");
    }
    eleData.endTime = value[1];
    // eleData.endTime = eleData.endTime.split("-")[1];
  } else {
    eleData.endTime = null;
  }
};

selectJs.setProgressTenThing = function(eleData) {
  if (eleData.ten === "0") {
    eleData.isCityTen = null;
    eleData.isAreaTen = true;
  } else if (eleData.ten === "1") {
    eleData.isCityTen = true;
    eleData.isAreaTen = null;
  } else if (eleData.ten === "2") {
    eleData.isCityTen = false;
    eleData.isAreaTen = false;
  } else {
    eleData.isCityTen = null;
    eleData.isAreaTen = null;
  }
};

selectJs.putAllMap = function(data, mapData) {
  Object.keys(mapData).forEach(function(key) {
    data[key] = mapData[key];
  });
};

selectJs.setOrgNames = function(data) {
  data.forEach(function(obj) {
    obj.orgNames = "";
    obj.orgIds.forEach(function(item) {
      if (item.name !== "") {
        obj.orgNames += item.name + ",";
      }
    });
    if (obj.orgNames && obj.orgNames.length > 0) {
      obj.orgNames = obj.orgNames.substr(0, obj.orgNames.length - 1);
    }
  });
};

Date.prototype.format = function(fmt) {
  var o = {
    "M+": this.getMonth() + 1,
    "d+": this.getDate(),
    "h+": this.getHours(),
    "m+": this.getMinutes(),
    "s+": this.getSeconds(),
    "q+": Math.floor((this.getMonth() + 3) / 3),
    S: this.getMilliseconds()
  };
  if (/(y+)/.test(fmt)) {
    fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  }
  for (var k in o) {
    if (new RegExp("(" + k + ")").test(fmt)) {
      fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
    }
  }
  return fmt;
};
export default selectJs;
